let server = require('express-xgx');

let contextRoot = '/dhxy/rest';
let userData = require('./mocks/apps/ams/user');
let departmentData = require('./mocks/apps/ams/department');
let classifyData = require('./mocks/apps/ams/classify');
let roleData = require('./mocks/apps/ams/role');
let menuData = require('./mocks/apps/ams/menu');
let menuTreeData = require('./mocks/apps/ams/user_menu');
let treeData = require('./mocks/apps/ams/tree');
let dictData = require('./mocks/apps/ams/dict');
let classifyTreeData = require('./mocks/apps/ams/classify_tree');
let baseArchivesData = require('./mocks/apps/ams/base_archives');
let attachmentData = require('./mocks/apps/ams/attachment');
let printArchiveIdsData = require('./mocks/apps/ams/print_archive_ids');
let printArchivesData = require('./mocks/apps/ams/print_archives');

server.post(contextRoot + '/login', function (req, res) {
    console.log(req.body);
    res.json({success: true,data:{user:{trueName:'1234'}},message:'登录成功'});
});

server.get(contextRoot + '/login', function (req, res) {
    res.json({success: true,data:{user:{trueName:'1234'}}});
});

server.get(contextRoot + '/logout', function (req, res) {
    res.json({success: true,message:'登出成功'});
});

server.get(contextRoot + '/basearchives/:code/basearchives/:id/file', function (req, res) {
    res.json({success: true, data: baseArchivesData.data[0]});
});
server.post(contextRoot + '/basearchives/:code/basearchives/:id/archived', function (req, res) {
    res.json({success: true,message:'archived'});
});
server.post(contextRoot + '/basearchives/:code/basearchives/:id/unArchived', function (req, res) {
    res.json({success: true,message:'unArchived'});
});
//user
server.post(contextRoot + '/users/:id/changePassword', function (req, res) {
    res.json({success: true,message:'修改成功'});
});
//print
server.get(contextRoot + '/prints/:code', function (req, res) {
    res.json(printArchiveIdsData);
});
server.get(contextRoot + '/prints/:code/basearchives', function (req, res) {
    res.json(printArchivesData);
});

server.generateCommonRest(contextRoot + '/users', userData);
//department
server.generateCommonRest(contextRoot + '/departments', departmentData);
//role
server.generateCommonRest(contextRoot + '/roles', roleData);
//tree
server.generateCommonRest(contextRoot + '/menus/tree', treeData);
//menu
server.generateCommonRest(contextRoot + '/menus', menuData);
//menu tree
server.generateCommonRest(contextRoot + '/menus/user/menus', menuTreeData);
//dict
// RestUtil.generateCommonRest(contextRoot + '/dics', dictData, app);
server.get(contextRoot + '/dics', function (req, res) {
    let rtn = {success:true,data:[]};

    if(req.query.type){
        rtn.data = dictData.data.filter(function (dic) {
            return dic.type == req.query.type
        });
    }
    else {
        rtn.data = dictData.data;
    }
    res.json(rtn);
});
//classify
server.generateCommonRest(contextRoot + '/classifies', classifyData);
//classify tree
server.generateCommonRest(contextRoot + '/basearchives/:code/tree', classifyTreeData);
//base_archives
server.generateCommonRest(contextRoot + '/basearchives/:code/basearchives', baseArchivesData);
//attachment
server.generateCommonRest(contextRoot + '/basefiles/:code/basefiles/:archivesId/basefiles', attachmentData);

server.start();
